package com.demo.dropdataack.service.common;


import com.alibaba.fastjson.JSONObject;
import com.demo.dropdataack.entity.BpmRequest;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;

/**
 * @author mm
 */
public class DropDataHelper {
    private static  String url = "http://bts.travelsky.com/gateway/openApi/pullService/getData/bpm/v1";
    @Autowired
    private OkHttpClient okHttpClient ;

    /**
     * 下发航易行的数据
     * @return
     */
    public BpmRequest DropData(String token ){
        BpmRequest BpmRequestBean = null;
        Request.Builder getBpmRequest = new Request.Builder().url(url).get().header("token", token);
        Call callBpm = okHttpClient.newCall(getBpmRequest.build());
        Response response = null;
        try {
            response = callBpm.execute();
            String data1 = response.body().string();
             BpmRequestBean = JSONObject.parseObject(data1, BpmRequest.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
       return  BpmRequestBean;
    }
}
